import { ICustomDialogOptions, IDialogHelper } from '@/core';
import { Modal, ModalFuncProps } from 'ant-design-vue';

export class DialogHelper implements IDialogHelper {
	/**
	 * @description 单例变量声明
	 * @protected
	 * @static
	 * @type {DialogHelper}
	 * @memberof AppFuncHelper
	 */
	protected static service: IDialogHelper;

	/**
	 * @description 获取实例
	 * @static
	 * @return {*}  {IDialogHelper}
	 * @memberof DialogHelper
	 */
	static getInstance(): IDialogHelper {
		if (!this.service) {
			this.service = new DialogHelper();
		}
		return this.service;
	}

	/**
	 * @description 成功提示
	 * @param {string} title 标题
	 * @param {string} message 内容
	 * @param {(...args: any[]) => any} [onOk] 确认回调
	 * @param {(...args: any[]) => any} [onCancel] 取消回调
	 * @memberof IDialogHelper
	 */
	success(
		title: string,
		message: string,
		onOk?: (...args: any[]) => any,
		onCancel?: (...args: any[]) => any
	): void {
		Modal.success({ title, content: message, onCancel, onOk });
	}

	/**
	 * @description 信息提示
	 * @param {string} title 标题
	 * @param {string} message 内容
	 * @param {(...args: any[]) => any} [onOk] 确认回调
	 * @param {(...args: any[]) => any} [onCancel] 取消回调
	 * @memberof IDialogHelper
	 */
	info(
		title: string,
		message: string,
		onOk?: (...args: any[]) => any,
		onCancel?: (...args: any[]) => any
	): void {
		Modal.info({ title, content: message, onCancel, onOk });
	}

	/**
	 * @description 警告提示
	 * @param {string} title 标题
	 * @param {string} message 内容
	 * @param {(...args: any[]) => any} [onOk] 确认回调
	 * @param {(...args: any[]) => any} [onCancel] 取消回调
	 * @memberof IDialogHelper
	 */
	warning(
		title: string,
		message: string,
		onOk?: (...args: any[]) => any,
		onCancel?: (...args: any[]) => any
	): void {
		Modal.warning({ title, content: message, onCancel, onOk });
	}

	/**
	 * @description 错误提示
	 * @param {string} title 标题
	 * @param {string} message 内容
	 * @param {(...args: any[]) => any} [onOk] 确认回调
	 * @param {(...args: any[]) => any} [onCancel] 取消回调
	 * @memberof IDialogHelper
	 */
	error(
		title: string,
		message: string,
		onOk?: (...args: any[]) => any,
		onCancel?: (...args: any[]) => any
	): void {
		Modal.error({ title, content: message, onCancel, onOk });
	}

	/**
	 * @description 确认提示
	 * @param {string} title 标题
	 * @param {string} message 内容
	 * @param {(...args: any[]) => any} [onOk] 确认回调
	 * @param {(...args: any[]) => any} [onCancel] 取消回调
	 * @memberof IDialogHelper
	 */
	confirm(
		title: string,
		message: string,
		onOk?: (...args: any[]) => any,
		onCancel?: (...args: any[]) => any
	): void {
		Modal.confirm({ title, content: message, onCancel, onOk });
	}

	/**
	 * 自定义提示
	 *
	 * @param {ICustomDialogOptions} options
	 * @memberof DialogHelper
	 */
	custom(options: ICustomDialogOptions): void {
		const modalOptions: ModalFuncProps = {
			title: options.title,
			content: options.content as unknown as string,
			closable: options.closable,
			okText: options.okText,
			cancelText: options.cancelText,
			onOk: options.ok,
			onCancel: options.cancel,
			width: options.width,
			keyboard: options.keyboard,
		};
		//  TODO 目前提示框类型未支持
		Modal.confirm(modalOptions);
	}
}
